package com.example.demo.controller;


import com.example.demo.common.Result;
import com.example.demo.pojo.AppAiChat;
import com.example.demo.service.IAppAiChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/aiChat")
public class AiChatController {

    @Autowired
    private IAppAiChatService iAppAiChatService;

    @RequestMapping(value = "/chat", method = RequestMethod.POST)
    public Result<?> chat(
            @RequestParam("userId") @Validated Integer userId,
            @RequestParam("sessionId") String sessionId,
            @RequestParam("message") String message) throws Exception {
        String chat = iAppAiChatService.chat(userId, sessionId, message);
        return Result.success(chat);
    }

    @RequestMapping(value = "/analysis", method = RequestMethod.POST)
    public Result<?> analysis(@RequestParam("userId") Integer userId,
                           @RequestParam("sessionId") String sessionId,
                           @RequestParam("filePath") String filePath) throws Exception {

        String fileContent = iAppAiChatService.analysis(userId, sessionId, filePath);
        return Result.success(fileContent);
    }


    @RequestMapping(value = "/history", method = RequestMethod.GET)
    public Result<?> history(@Validated @RequestParam("userId") Integer userId) throws Exception {
        List<AppAiChat> appAiChats = iAppAiChatService.historyList(userId);
        return Result.success(appAiChats);
    }

    @RequestMapping("/sessionAll")
    public List<AppAiChat> sessionAll(@RequestParam("sessionId") String sessinId) throws Exception {
        List<AppAiChat> appAiChats = iAppAiChatService.sessionAll(sessinId);
        return appAiChats;
    }


    @RequestMapping("/updateName")
    public void updateName(@RequestParam("name") String name, @RequestParam("sessionId") String sessionId) throws Exception {
        iAppAiChatService.updateName(sessionId, name);
        return;
    }

    @RequestMapping("/deleteSession")
    public void deleteSession(@RequestParam("sessionId") String sessionId) throws Exception {
        iAppAiChatService.deleteSession(sessionId);
        return;
    }

}
